package main

import (
	"fmt"
	"strconv"
)

// channel
func main() {
	fruits := make(chan []string)
	numbers := make(chan int)

	go func() {
		for i := 0; i < 100; i++ {
			numbers <- i
		}
		close(numbers)
	}()

	go func() {
		f := []string{"水果"}
		for x := range numbers {
			if x%2 == 0 {
				fruits <- append(f, strconv.Itoa(x))
			} else {
				fruits <- nil
			}
		}
		close(fruits)
	}()

	// range循环可直接在channels上面迭代，channel被关闭并且没有值可接收时跳出循环
	for fruit := range fruits {
		fmt.Println(fruit)
	}
}
